package com.wjc.business.controller.admin.web;


import com.wjc.business.BusinessApplication;
import com.wjc.server.dto.CommonDto;
import com.wjc.server.dto.MemberCourseDto;
import com.wjc.server.dto.PageDto;
import com.wjc.server.service.MemberCourseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController("webMemberCourseController")
@RequestMapping("/web/member-course")
public class MemberCourseController {

    private static final Logger LOG= LoggerFactory.getLogger(BusinessApplication.class);
    public static final String BUSINESS_NAME = "会员课程报名";

    @Resource
    private MemberCourseService memberCourseService;

    //查询
    @GetMapping("/list")
    public CommonDto list(@Valid  PageDto pageDto){
         memberCourseService.list(pageDto);
//         LOG.info("分页有啥: {}",pageDto);
        CommonDto<PageDto> pageDtoCommonDto = new CommonDto<>();
        pageDtoCommonDto.setContent(pageDto);
        return pageDtoCommonDto;
    }

    //保存
    @PostMapping("/save")
    public CommonDto list(@Valid @RequestBody MemberCourseDto memberCourseDto){
        CommonDto commonDto=new CommonDto<>();
        memberCourseService.save(memberCourseDto);
        return commonDto;

    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonDto delete(@PathVariable Long id){
        CommonDto commonDto=new CommonDto<>();
        memberCourseService.delete(id);
        return commonDto;
    }


    /**
     * 报名
     */
    @PostMapping("/enroll")
    public CommonDto enroll(@RequestBody MemberCourseDto memberCourseDto) {

        CommonDto responseDto = new CommonDto();
        memberCourseDto = memberCourseService.enroll(memberCourseDto);
        responseDto.setContent(memberCourseDto);
        return responseDto;
    }

    /**
     * 获取报名信息
     */
    @PostMapping("/get-enroll")
    public CommonDto getEnroll(@RequestBody MemberCourseDto memberCourseDto) {
        CommonDto responseDto = new CommonDto();
        memberCourseDto = memberCourseService.getEnroll(memberCourseDto);
        responseDto.setContent(memberCourseDto);
        return responseDto;
    }

}
